//
//  StatusForwardCell.swift
//  nimabi
//
//  Created by danny on 15/7/9.
//  Copyright © 2015年 DannyLiu. All rights reserved.
//

import UIKit
import FFAutoLayout

class StatusForwardCell: StatusCell {

    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        
        // 初始化转发微博的文本
        forwardLabel = UILabel(color: UIColor.darkGrayColor(), fontSize: 11, mutiLines: true)
        forwardLabel.preferredMaxLayoutWidth = UIScreen.mainScreen().bounds.width - 16
        
        // 测试转发微博的文本
//        forwardLabel.text = "sajidajdjasdjaisjdiaoj电视剧埃及的撒基地啊打四季度阿斯觉得iasjdia设计的阿斯顿就阿斯顿就爱上大家爱上地撒大家死啊点击撒"
        
        // 先插到底层
        insertSubview(forwardLabel, atIndex: 0)
        
        
        forwardBtn.backgroundColor = UIColor(white: 0.9, alpha: 1.0)
        // 在插入底层,这样btn在label的后面,在最底层
        insertSubview(forwardBtn, atIndex: 0)
        
        // 设置按钮以及label的自动布局
        forwardBtn.ff_AlignVertical(ff_AlignType.BottomLeft, referView: contentLabel, size: nil, offset: CGPoint(x: -12, y: 12))
        forwardBtn.ff_AlignVertical(ff_AlignType.TopRight, referView: footerView, size: nil)
        
        forwardLabel.ff_AlignInner(ff_AlignType.TopLeft, referView: forwardBtn, size: nil, offset: CGPoint(x: 12, y: 12))
        
        // 添加判断 是否有转发微博
        let cons = forwardLabel.text == nil ? pictureView.ff_AlignVertical(ff_AlignType.BottomLeft, referView: contentLabel, size: CGSizeZero, offset: CGPoint(x: 0, y: 12)) : pictureView.ff_AlignVertical(ff_AlignType.BottomLeft, referView: forwardLabel, size: CGSize(width: 290, height: 90), offset: CGPoint(x: 0, y: 12))
        
        // 记录宽高的约束
        widthCons = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Width)
        heightCons = pictureView.ff_Constraint(cons, attribute: NSLayoutAttribute.Height)
        
    }

    required init(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    
    /// 懒加载后面的背景按钮
    lazy var forwardBtn = UIButton()
    /// 懒加载转发微博label
    lazy var forwardLabel = UILabel()

}
